using JT808Protocol.Common;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy.Location
{
    /// <summary>
    /// 位置信息批量上报
    /// </summary>
    public class DrLocationBatchReport_0x0704 : IJT808Body
    {
        /// <summary>
        /// 数据项个数
        /// </summary>
        [JsonPropertyName("数据项个数")] public ushort ItemCount { get; set; }

        /// <summary>
        /// 上报类型 ：0 正常批量上报，1 盲目区补报
        /// </summary>
        [JsonPropertyName("上报类型")] public byte DataType { get; set; }

        /// <summary>
        /// 位置信息列表
        /// </summary>
        [JsonPropertyName("位置信息列表")] public List<DrLocation_0x0200> BatchLocation { get; set; }

        public override IJT808Body ReadBody(ReadOnlySpan<byte> source, ref int index)
        {
            // 数据项个数
            ItemCount = ParseHelper.Uint16(ref source, index);
            index += 2;

            // 位置数据类型
            DataType = source[index];
            index++;

            BatchLocation = new List<DrLocation_0x0200>();
            for (int i = 0; i < ItemCount; i++)
            {
                //位置汇报数据体长度，n
                var reportLocationLen = ParseHelper.Uint16(ref source, index);
                index += 2;

                var location = new DrLocation_0x0200();
                location.ReadBody(source, index, reportLocationLen);
                BatchLocation.Add(location);

                index += reportLocationLen;
            }

            return this;
        }

        public override List<byte> WriteToBytes()
        {
            throw new NotImplementedException();
        }
    }
}